$(function () {
    $('#btnQuery').click(function () {
      let keyword = $('[name=keyword]').val()
      let obj = {
        keyword,
      }
      $.post('/test/query', obj, function (res) {
        console.log(res);
        $('.tbRow').html('')
        res.forEach(item=>{
          let html=`
          <tr class="tbRow">
              <td>${item.id}</td>
              <td>${item.productName}</td>
              <td>${item.supplier}</td>
              <td>${item.price}</td>
              <td>${item.stock}</td>
              <td>${item.remarks}</td>
              <td>
                  <input class="btnEdit" onclick="btnEdit(${item.id})" type="button" value="编辑">
                  <input class="btnDel" onclick="btnDel(${item.id})" type="button" value="删除">
              </td>
          </tr>
          `
          $('#tbData').append(html)
        })
      })
    })
    $('#btnAdd').click(function () {
      window.location.href = `/test/wer`
    })
    $('#btnSave').click(function () {
      let id = $('[name=id]').val()
      let productName = $('[name=productName]').val()
      let supplier = $('[name=supplier]').val()
      let price = $('[name=price]').val()
      let stock = $('[name=stock]').val()
      let remarks = $('[name=remarks]').val()
      let obj = {
        id,
        productName: productName,
        supplier,
        price,
        stock,
        remarks,
      }
      console.log(obj)
      $.post('/test/save', obj, function () {
        alert('保存成功')
        window.location.href = `/test/pow`
      })
    })
    $('#btnCancel').click(function () {
      window.location.href = `/test/pow`
    })
  })
  function btnEdit(id) {
    window.location.href = `/test/wer/${id}`
  }
  
  function btnDel(id) {
      window.location.href = `/test/Delete/${id}`
  }